Home:ALL Converter>Struts 2 - populate dropdownlist from database

Struts 2 - populate dropdownlist from database

Ask Time:2020-02-24T00:49:59         Author:Jherica Tiu

Json Formatter

Please help me, I'm having an error in the dropdown list. We tried to populate the dropdown using the MySQL database but it doesn't work and then we tried to hardcode the dropdown and it works. Am I doing it wrong? I would highly appreciate your answers Thank you!!

jsp

<s:form action='Admin' method='post'>
   <s:select label="Select Clinic"
      name="clinicChoices"
      headerValue="Select Clinic"
      list="%{clinicChoices}"
   />

controller

private List<String> clinicChoices;

public List<String> getClinicChoices() {
    return clinicChoices;
}

public void setClinicChoices(List<String> clinicChoices) {
    this.clinicChoices = clinicChoices;
}

@Override
public void prepare() throws Exception {

    clinicChoices =new ArrayList<String>();
    ResultSet rs=ClinicBean.getAllRecords();
    while(rs.next()){
        clinicChoices.add(rs.getString("clinicName"));          
    }       
}

 public String clinicList() throws Exception{
      return SUCCESS;
}

This is the error message:

tag 'select', field 'list', name 'clinicChoices': The requested list key '%{clinicChoices}' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]

Author:Jherica Tiu,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60364535/struts-2-populate-dropdownlist-from-database
yy